const util = require('./util.js')
const baseurl = util.baseurl
import SHA256 from 'js-sha256'
export { staff_login, volunteer_login, staff_register, volunteer_register };

// 职工登录请求
const staff_login = (account, password) => {
    let password_process=SHA256(password)
    return new Promise((resolve, reject) => {
        wx.request({
            url: baseurl + '/User/StaffLogin',
            method: 'POST',
            header: {
                'content-type': 'application/json'
            },
            data: {
                'UserName': account,
                'Password': password_process
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
// 志愿者登录请求
const volunteer_login = (account, password) => {
    let password_process=SHA256(password)
    return new Promise((resolve, reject) => {
        wx.request({
            url: baseurl + '/Volunteer/Login',
            method: 'POST',
            header: {
                'content-type': 'application/json'
            },
            data: {
                'UserName': account,
                'Password': password_process,
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
// 职工注册请求
const staff_register = (data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: baseurl + '/User/RegisterUser',
            method: 'POST',
            data: data,
            header: {
                'content-type': 'application/json'
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
// 志愿者注册请求
const volunteer_register = (data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: baseurl + '/Volunteer/Register',
            method: 'POST',
            data: data,
            header: {
                'content-type': 'application/json'
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}